package edu.uts.reekie.designer.implementation.model;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.swt.graphics.Image;

import edu.uts.reekie.designer.ImageHelper;
import edu.uts.reekie.designer.model.Nameable;
import edu.uts.reekie.designer.model.ViewNode;


public class ViewExternalInterface extends ViewNode implements Nameable {
	
	// properties
	public static String PROPERTY_NAME = "name";
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1;

	private static Image ICON = ImageHelper.createFromConceptualModelResource( "icons/externalinterface16.gif");  //$NON-NLS-1$
	
	private static int count;
	
	public ViewExternalInterface() {
		super();
		// set some default values
		setName(getID().toString()); 
	}
	
	
	private String name;
	
	/* (non-Javadoc)
	 * @see edu.uts.reekie.designer.model.Nameable#getName()
	 */
	public String getName(){
		return name;
	}
	
	/* (non-Javadoc)
	 * @see edu.uts.reekie.designer.model.Nameable#setName(java.lang.String)
	 */
	public void setName(String name){
		String oldName = this.name;
		this.name = name;
		firePropertyChange(PROPERTY_NAME, oldName, name); 
		
	}
	
	public Image getIconImage() {
		return ICON;
	}

	protected String getNewID() {
		return Integer.toString(count++);
	}

	public String toString() {
		return "Interface \"" + name + "\""; 
	}
	
	public Dimension getSize(){
		return new Dimension(-1, -1);
	}
	
	/**
	 * Nulls out any changes to this and its subclasses as
	 * they are of fixed size.
	 */
	public void setPropertyValue(Object id, Object value){
		if(PROPERTY_SIZE.equals(id)) 
			super.setPropertyValue(id,new Dimension(getSize()));
		else
			super.setPropertyValue(id,value);
	}
	
	
	
}
